//
//  ServiceCell.swift
//  AESOLAR_IOS
//
//  Created by Mr.Wang on 2019/10/16.
//  Copyright © 2019 Mr.Wang. All rights reserved.
//

import UIKit

class ServiceCell: UITableViewCell {

    let contentBackgroundView = UIView()
    let iconImageView = UIImageView()
    let nameLabel = UILabel()
    let detailNameLabel = UILabel()
    let countLabel = UILabel()
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = UIColor.clear
        self.selectionStyle = .none
        
        let layerView = UIView()
        layerView.backgroundColor = .white
        layerView.layer.cornerRadius = 8
        layerView.layer.shadowColor = UIColor.black.cgColor
        layerView.layer.shadowOffset = .zero
        layerView.layer.shadowRadius = 4
        layerView.layer.shadowOpacity = 0.1
        self.addSubview(layerView)
        layerView.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.equalTo(13)
            make.right.equalTo(-13)
            make.bottom.equalTo(-15)
        }
        
        contentBackgroundView.backgroundColor = .white
        contentBackgroundView.layer.cornerRadius = 8
        contentBackgroundView.layer.masksToBounds = true
        layerView.addSubview(contentBackgroundView)
        contentBackgroundView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        let imageView = UIImageView()
        imageView.image = UIImage.init(named: "setvice_next")
        contentBackgroundView.addSubview(imageView)
        imageView.snp.makeConstraints { (make) in
            make.right.equalTo(-15)
            make.top.equalTo(15)
            make.height.width.equalTo(24)
        }
        
        contentBackgroundView.addSubview(iconImageView)
        iconImageView.snp.makeConstraints { (make) in
            make.left.equalTo(-15)
            make.bottom.equalTo(10)
            make.height.width.equalTo(120)
        }
        
//        nameLabel.adjustsFontSizeToFitWidth = true
        nameLabel.numberOfLines = 0
        nameLabel.font = UIFont.systemFont(ofSize: 16, weight: .bold)
        contentBackgroundView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconImageView.snp.right).offset(28)
            make.top.equalTo(iconImageView.snp.top)
            make.right.lessThanOrEqualTo(imageView.snp.left).offset(-10)
        }
        
        detailNameLabel.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        detailNameLabel.textColor = #colorLiteral(red: 0.6, green: 0.6, blue: 0.6, alpha: 1)
        detailNameLabel.numberOfLines = 0
        contentBackgroundView.addSubview(detailNameLabel)
        detailNameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(nameLabel.snp.left)
            make.right.equalTo(imageView.snp.left)
            make.top.equalTo(nameLabel.snp.bottom).offset(12)
        }
        
        countLabel.textAlignment = .center
        countLabel.layer.masksToBounds = true
        countLabel.backgroundColor = .red
        countLabel.layer.cornerRadius = 8
        countLabel.textColor = .white
        countLabel.font = UIFont.systemFont(ofSize: 13)
        contentBackgroundView.addSubview(countLabel)
        countLabel.snp.makeConstraints { (make) in
            make.centerY.equalTo(nameLabel.snp.top)
            make.left.equalTo(nameLabel.snp.right).offset(5)
            make.height.width.equalTo(16)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    

}
